Hi anyone I want to pass value from php to c by use php value as argument to run c program but c program can’t be seen any value from php
This code of php :
enter code here
<form action="create.php" method="post">
Create VM on website <br>
VM Name
<input type="text" name="vm_n" value="" />
VM Ram
<input type="text" name="vm_r" value="" />
VM Virtual CPU
<input type="text" name="vm_c" value="" />
VM File size
<input type="text" name="vm_fs" value="" />
VM File OS
<input type="text" name="vm_b" value="" />
<input type="submit" name="button1" value="Submit" />
</form>
<?php
//Check wihch Submit was clicked and pass from php
$vm_n[10]=$_POST['vm_n'];
$vm_r[5]=$_POST['vm_r'];
$vm_c[3]=$_POST['vm_c'];
$vm_fs[5]=$_POST['vm_fs'];
$vm_b=[8]$_POST['vm_b'];
if ($_POST['button1']) {
echo "Creating VM.......";
$last_line = system('/var/local/vmweb/create_vm install -n $vm_n -r $vm_r -c $vm_c -fs $vm_fs -b $vm_b', $retval);
echo '
</pre>
<hr />Status Output: ' . $last_line . '
<hr />Status Output: ' . $vm_n . '
<hr />Status Output: ' . $vm_r . '
<hr />Status Output: ' . $vm_c . '
<hr />Status Output: ' . $vm_fs . '
<hr />Status Output: ' . $vm_b . '
<hr />Return value: ' . $retval;
}
?>
and this code of C program :
if (!(initsetuid())){
exit(1);
}
// Check what command is asked
if (argc==1)
{
fprintf (stderr, "Missing Agument to Create VM command!\n");
return 1;
}
if (argc==12 && strcmp(argv[1], OP_INSTALL)==0) {
if (argc==12 && strcmp(argv[2], "-n")==0) {
printf("Argument is : %s Parameter is: %s \n", argv[2],argv[3]);
sprintf (vm_name,argv[3]);
//printf("vm_name is : %s \n",vm_name);
}
I’m use if else to catch some argument on string
need you help me please !! thank you
In this line
You are using single quotes to surround variables in the string, PHP doesn’t work that way. Use double quotes instead.
Also
I think you’ve missed out an ‘=’ here:You’ve put the ‘=’ in the wrong place:Should be:
Wait a minute!
I think all of this bit is wrong!
You are creating arrays with the above code, and I don’t believe that’s really what you want..
Try this instead: