Jump to content

is this the correct syntax?


frijole

Recommended Posts

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:joelklabo@gmail.com">
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
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

<?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
Share on other sites

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
Share on other sites

use my code man it will work trust me ;D

 

 

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.