frijole Posted March 7, 2008 Share Posted March 7, 2008 I am trying to build a CMS for my site so I can add videos with a description to my DB. I am not sure if this makes sense? <table> <tr> <td> <form method="post" action="mailto:[email protected]"> Embed HTML:</td><td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML"> Enter Embed HTML Here </textarea></td></tr> <br /> <tr><td> Description: </td><td> <textarea rows="5" cols="50" wrap="physical" name="description"> Describe The Video Here </textarea></td></tr> <tr><td> <input type="submit" value="Add Video!"> </form> </td></tr> </table> <?php require_once "dbConnect.php"; $embedHTML = mysql_real_escape_string($_POST['embedHTML']); $videoDesc = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; mysql_query($query) or die("could not insert data into database"); ?> Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/ Share on other sites More sharing options...
phpnoobie9 Posted March 7, 2008 Share Posted March 7, 2008 Take action="mailto:[email protected]" and replace it with whatever php file you have with your php code. Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485690 Share on other sites More sharing options...
Naez Posted March 7, 2008 Share Posted March 7, 2008 Besides redoing the mailto of the form, have it echo itself. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Then do: <?php if ($_POST['embedhtml'] && $_POST['description']) { require_once "dbConnect.php"; $embedHTML = mysql_real_escape_string($_POST['embedHTML']); $videoDesc = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; mysql_query($query) or die("could not insert data into database"); echo "Video entered into DB"; } ?> Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485749 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 i made those modifications, but when i execute nothing happens. The form reappears and nothing new is echoed to the screen. Any ideas? My connection: <?php // Database settings define("HOST", "localhost"); define("DBUSER", "********"); define("PASS", "********"); define("DB", "********"); // MySQL connection $conn = mysql_connect(HOST, DBUSER, PASS); if (!conn) { // the connection failed so quit the script die('Could not connect !<br />Please contact the site\'s administrator.'); } $db = mysql_select_db(DB); if (!db) { // cannot connect to the database so quit the script die('Could not connect to database <br /> Please contact the site\'s administrator.'); } ?> And the add video script: <?php if ($_POST['embedHTML'] && $_POST['description']) { require_once "dbConnect.php"; $embedHTML = mysql_real_escape_string($_POST['embedHTML']); $videoDesc = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; mysql_query($query) or die("could not insert data into database"); echo "video added to the DB!"; } else { die("the fileds are empty") } ?> <html> <table> <tr> <td> <form method="post" action="videoSubmit.php"> Embed HTML:</td> <td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML"> Enter Embed HTML Here </textarea></td> </tr> <tr> <td>Description: </td> <td><textarea rows="5" cols="50" wrap="physical" name="description"> Describe The Video Here </textarea></td> </tr> <tr> <td><input type="submit" value="Add Video!"></form></td> </tr> </table> </html> Any help would be greatly appreciated. Or any constructive criticisms. Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485774 Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 <?php if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once "dbConnect.php"; $embedHTML = mysql_real_escape_string($_POST['embedHTML']); $videoDesc = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; $result2=mysql_query($query) or die(mysql_error()); if($result2){ echo "video added to the DB!";} } elseif(empty($result2)){ echo "The Fields Are empty";} ?> Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485786 Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 <?php if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once("dbConnect.php"); $embedHTML = trim(mysql_real_escape_string($_POST['embedHTML'])); $videoDesc = trim(mysql_real_escape_string($_POST['description'])); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; $result2=mysql_query($query) or die(mysql_error()); } if($result2){ echo "video added to the DB!";} elseif(empty($result2)){ echo "The Fields Are empty";} ?> Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485797 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 I just tried it again and got this error: Parse error: syntax error, unexpected '{' in /home/thinksna/public_html/videoSubmit.php on line 10 and this is line 10: $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; anything out of the ordinary? Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485813 Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 <?php $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; ?> should be: <?php $query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)";?> Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485826 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 nice, that worked. now: Parse error: syntax error, unexpected '}' in /home/thinksna/public_html/videoSubmit.php on line 23 this is line 23: else { die("the fileds are empty") } Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485828 Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 use my code man it will work trust me your reverting back to your old code and adding bits and pieces of mine <?php if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once("dbConnect.php"); $embedHTML = trim(mysql_real_escape_string($_POST['embedHTML'])); $videoDesc = trim(mysql_real_escape_string($_POST['description'])); $query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)"; $result2=mysql_query($query) or die(mysql_error()); } if($result2){ echo "video added to the DB!";} elseif(empty($result2)){ echo "The Fields Are empty";} ?> Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485831 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 what is the best way to incorporate the form into this? Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485833 Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 <?php if ($_POST) {?> form here <?php }else{ if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once("dbConnect.php"); $embedHTML = trim(mysql_real_escape_string($_POST['embedHTML'])); $videoDesc = trim(mysql_real_escape_string($_POST['description'])); $query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)"; $result2=mysql_query($query) or die(mysql_error()); } if($result2){ echo "video added to the DB!";} elseif(empty($result2)){ echo "The Fields Are empty";} } ?> Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485835 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 So I wouldn't echo the form. Just place between the to php blocks? Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485841 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 I am now getting this error: Parse error: syntax error, unexpected $end in /home/thinksna/public_html/videoSubmit2.php on line 43 And here is the new version of the whole script: <?php if($_POST){?> <html> <table> <tr> <td> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> Embed HTML:</td> <td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML"> Enter Embed HTML Here </textarea></td> </tr> <tr> <td>Description: </td> <td><textarea rows="5" cols="50" wrap="physical" name="description"> Describe The Video Here </textarea></td> </tr> <tr> <td><input type="submit" value="Add Video!"></form></td> </tr> </table> </html> <?php if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once("dbConnect.php"); $embedHTML = trim(mysql_real_escape_string($_POST['embedHTML'])); $videoDesc = trim(mysql_real_escape_string($_POST['description'])); $query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)"; $result2=mysql_query($query) or die(mysql_error()); } if($result2){ echo "video added to the DB!";} elseif(empty($result2)){ echo "The Fields Are empty";} ?> line 43 is the very last line of code. just ?> Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485842 Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 doood are you even listening? copy the exact code i posted above or u will get errors Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485843 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 thats what i did. Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485845 Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 um no you obviously did not or else there would be an else statement in the bottom which there is not Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485846 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 ok, i got it now. thanks for all your help. Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-485848 Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 the script is running now but MySQL doesn't like the query its getting. Here is the query: $query = "INSERT INTO videos (embed_html, description) VALUES ($embedHTML,$videoDesc)"; Any ideas? Link to comment https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/#findComment-486287 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.